package com.czx.controller;

import com.czx.common.security.UserTokenThreadLocal;
import com.czx.service.LikeService;
import com.czx.common.utils.R;
import com.czx.service.SysMessageService;
import com.czx.vo.LikeVo;
import com.czx.vo.UserToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LikeController {
    @Autowired
    private LikeService likeService;
    @RequestMapping("/like")
    @ResponseBody
    public R click(@RequestBody LikeVo likeVo){
        //判断用户是否登录
        UserToken userToken = UserTokenThreadLocal.get();
        if (userToken == null) {
            return R.fail("请先登录");
        }
        //把登录的用户id封装到likeVo
        likeVo.setUserId(userToken.getUser().getId());
        //实现点赞
        likeService.click(likeVo);
        return R.success();
    }

}
